<?php

/**
 * Unit testing functions
 *
 * @category   Pone
 * @package    Pone_UnitTest
 * @author     Pham Cong Dinh (a.k.a pcdinh)
 * @since      October 19, 2008
 * @copyright  Pham Cong Dinh (http://www.phpvietnam.net)
 * @license    http://www.phpvietnam.net/license/ PHPVietnam License
 * @version    $Id: testingfunctions.php 6 2008-12-26 12:40:02Z pcdinh $
 */

/**
 * Will be true if the value is true
 *
 * @param mixed $test Condition to test, evaluated as boolean
 * @param string $message Descriptive message to output upon test
 */
function assertTrue($test, $message)
{
    static $count;

    if (!isset($count))
    {
        $count = array('pass' => 0, 'fail' => 0, 'total' => 0);
    }

    $mode = $test ? 'pass' : 'fail';
    printf("%s: %s (%d of %d tests run so far have %sed)\n",
    strtoupper($mode), $message, ++$count[$mode], ++$count['total'], $mode);
}

/**
 * Will be true if the value is null
 *
 * @param  null   $value   Supposedly null value.
 * @param  string $message Message to display.
 * @return bool            True on pass
 */
function assertNull($value = null, $message = "%s")
{
    return assertTrue(!isset($value), $message);
}

/**
 * Will be true if the value1 is equal to value2
 *
 * @param  mixed $value1   Type of this value can be object, string, integer, float.
 * @param  mixed $value2   Type of this value can be object, string, integer, float.
 * @param  string $message Message to display.
 * @return bool            True on pass
 */
function assertEqual($value1, $value2, $message)
{
    return assertTrue($value1 === $value2, $message);
}

?>